<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%-- 引入页面头 --%>
<%@ include file="/pageHead.jsp"%>
<form name="form1" id="form1" action="<%-- ${systemctx}/sample/saveSample.web --%>" method="post">
	<div class="pageMain">
		<div class="pageTitle"><%=MessageResourcesUtils.getMessage(request, "systemmanage.bascsetting.title") %><span></span><%=MessageResourcesUtils.getMessage(request, "systemmamage.dutymanage.dutyset.dutyList.title") %><span></span><%=MessageResourcesUtils.getMessage(request, "systemmamage.dutymanage.dutyset.dutyAdd.title") %></div>
		<div class="pageBody">
			<div class="form-group">
				<ul>
					<li>
						<i>*</i>
						<label><%=MessageResourcesUtils.getMessage(request, "systemmamage.dutymanage.dutyset.dutyList.dutycode") %></label>
						<span><input type="text" id="dutycode" name="dutycode" value="" class="validate[required,maxSize[10]]"/></span>
					</li>
					<li>
						<i>*</i>
						<label><%=MessageResourcesUtils.getMessage(request, "systemmamage.dutymanage.dutyset.dutyList.dutyname") %></label>
						<span><input type="text" id="dutyname" name="dutyname" value="" class="validate[required,maxSize[20]]"/></span>
					</li>
				</ul>
			</div>	
			<!-- 分配服务菜单权限 start -->
			<div  style="border: 1px solid #e0e0e0;background:#fff;padding-top: 9px;height:350px;width: 99%;">
				<span style="color: red;padding-left: 5px;padding-right: 6px">*</span><%=MessageResourcesUtils.getMessage(request, "dailyoperation.services.servicesAdd.fenpeimenu") %>
	       		<div  style="margin-top: 9px;height:300px;overflow-y:auto;">
	       			<ul id="menuTree" class="ztree" style="padding-left: 13px;"></ul>
	       		</div>
       		</div>
			 	<!-- 分配服务菜单权限end -->
			<div class="button-group" style="padding-top: 10px">
			<input type="hidden" id="menuids" name="menuids" value="">
			<input type="button" class="btn btn-default"  id="butSave" name="butSave" value='<%=MessageResourcesUtils.getMessage(request, "common.button.save") %>' />
       		<input type="button" class="btn btn-default"  id="butReturn" name="butReturn" value='<%=MessageResourcesUtils.getMessage(request, "common.button.back") %>' />
			</div>
		</div>
	</div>
</form>
<script type="text/javascript">
	$(document).ready(function() {
		function asyncMenu(){
			var zTree = $.fn.zTree.getZTreeObj("menuTree");
			asyncMenuNodes(zTree.getNodes());
			//zTree.expandAll(true);//true表示所有父节点全部展开
		}
		
		function asyncMenuNodes(nodes){
			if(!nodes) return;
			var zTree = $.fn.zTree.getZTreeObj("menuTree");
			for (var i=0, l=nodes.length; i<l; i++) {//遍历外层节点
				if (nodes[i].isParent && nodes[i].zAsync) {//如果是父节点并且父节点没有加载过
					asyncMenuNodes(nodes[i].children);//在这种条件下继续递归遍历该父节点的所有子节点
				} else {//如果不是父节点或者父节点已经加载过
					zTree.reAsyncChildNodes(nodes[i], "refresh", true);//清空后不展开父节点，其他值或缺省状态都自己展开
				}
			}
		}

		function onCheck(event, treeId, treeNode){
	        var treeObj=$.fn.zTree.getZTreeObj("menuTree"),
	        nodes=treeObj.getCheckedNodes(true),
	        menuids ="";
	        for(var i=0;i<nodes.length;i++){
	            menuids+=nodes[i].menuid + ",";
	        }
	       	$('#menuids').val(menuids);
	    }
		
		var menusetting = {
				async: {
					enable:true,
					url:"${systemctx}/systemmamage/dutymanage/dutyset/queryMenuDirectoryTree.json",
					autoParam: ["menucode","menulevel"]
				},check:{
					enable:true
				},data:{
					simpleData:{
						enable:true,
						idKey:"menucode",
						rootPid:0
					}
				},callback:{
					onAsyncSuccess:asyncMenu,
					onCheck:onCheck
				}
		};
		
		$.fn.zTree.init($("#menuTree"), menusetting);//初始化zTree，第三个参数没有则表明用异步加载
		var zTree2 = $.fn.zTree.getZTreeObj("menuTree");
		if(zTree2  != null){
			zTree2.setting.check.chkboxType = { "Y" : "ps", "N" : "ps"};//checkbox（Y）勾选后和取消（N）都对父节点（p）和对子节点（s）有影响
		}
		
		$('#butSave').click(function() {
			
			var exp = $('#form1').validationEngine('validate');
			var menuid_value = $('#menuids').val();
			
			if(exp==true)
			{
				if(menuid_value == ""){
					alert('<%=MessageResourcesUtils.getMessage(request, "systemmamage.dutymanage.dutyset.dutyAdd.alert2")%>');
				}else{
					// 显示进度条
					showSending();
					$.ajax({
						type: 'POST',
					    url: '${systemctx}/systemmamage/dutymanage/dutyset/validattionDuty.json',
					    data: $("#form1").serialize(),
					    dataType: 'json',
					    success: function(data)
					    {
					    	//关闭执行...
							closeSending();
					    	if (data.messagetype == '2')
					    	{
					    		//显示AJAX请求后的提示信息
								$.fn.ajaxmessage(data);
					    	}
					    	else
					    	{
					    		showSending();
					    		form1.action="${systemctx}/systemmamage/dutymanage/dutyset/addDuty.web";
								form1.submit();
					    	}
					    }
					}); 
				} 
			}   
		});
	
		$('#butReturn').click(function(){
			parent.document.location.reload();
		    $.fn.closeIssWindow();
		});
	});
</script>
<%-- 引入页面尾 --%>
<%@ include file="/pageFloor.jsp"%>